package com.gxa.common;

import com.gxa.utils.Constants;

/**
 * 返回数据公共对象
 */
public class R<T> {
    private Integer code; // 状态码
    private String message; // 提示信息
    private T data; // 返回数据

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public R() {

    }

    public R(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public R(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static R success(){
        return new R(Constants.OK,Constants.MESSAGE_OK);
    }

    public static R success(String message){
        return new R(Constants.OK,message);
    }

    public static R success(Integer code,String message){
        return new R(code,message);
    }

    public static <T> R<T> success(T data){
        return new R(Constants.OK,Constants.MESSAGE_OK,data);
    }

    public static <T> R<T> success(String message,T data){
        return new R(Constants.OK,message,data);
    }

    public static R error(){
        return new R(Constants.ERROR,Constants.MESSAGE_ERROR);
    }

    public static R error(String message){
        return new R(Constants.ERROR,message);
    }

    public static R error(Integer code,String message){
        return new R(code,message);
    }
}
